package demo.day10;

import java.util.Objects;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/1-08-01-18:43
 * @Description：demo.day10
 */
public class Circle extends GeometricObject{
    private double radius;
    public Circle(){}
    public Circle(double radius){
        this.radius = radius;
    }
    public Circle(double radius,String color){
        super(color);
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }
    public double sumArea(){
        return radius*radius*Math.PI;
    }
    @Override
    public boolean equals(Object obj){
        if(obj == this){
            return true;
        }
        if(obj == null || this.getClass() != obj.getClass()){
            return false;
        }
        Circle circle = (Circle) obj;
        return circle.radius == this.radius;
    }

    @Override
    public String toString() {
        return "Circle{" +
                "radius=" + radius +
                '}';
    }

    public static void main(String[] args) {
        Circle circle1 = new Circle(2);
        Circle circle2 = new Circle(2.0);
        System.out.println("圆的面积为：" + circle1.sumArea());
        System.out.println("两个圆的半径是相等的： " + circle1.equals(circle2));
        System.out.println(circle1);
    }
    //    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Circle circle = (Circle) o;
//        return Double.compare(circle.radius, radius) == 0;
//    }
//
//    @Override
//    public int hashCode() {
//        return Objects.hash(radius);
//    }
}
